package com.foton.logistic.util.net;


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.foton.logistic.util.SharedUtil;
import com.foton.logistic.util.tool.LogUtil;
import com.foton.logistic.util.tool.StringUtil;

import java.util.HashMap;
import java.util.Map;


public class HttpUtil {


    public static boolean isnet(Context paramContext) {
        ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                .getSystemService("connectivity");

        while (true) {
            // 获取代表联网状态的NetWorkInfo对象
            NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
            if ((localNetworkInfo != null) && (localNetworkInfo.isConnected())) {
                //
                if (localNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }

            return false;
        }
    }


    /**
     * make true current connect service is wifi
     *
     * @param mContext
     * @return
     */
    private static boolean isWifi(Context mContext) {
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null
                && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
        return false;
    }

    public static int netWork(Context mContext) {
        ConnectivityManager connectivityManager = (ConnectivityManager) mContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        if (activeNetInfo != null) {
            if (activeNetInfo.isConnected()) {
                if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                    return 2;
                }
                if (activeNetInfo.getState() == NetworkInfo.State.CONNECTED) {
                    return 1;
                }
            }
            return 0;
        }
        return 0;
    }

    public static Map<String, Object> getEncryMap() {
        Map<String, Object> arg = new HashMap<String, Object>();
        //arg.put("token","3d0698bac419ca50fd4abe81f75154ed");
        arg.put("token","acbc61ddcad5375b450ac5c6e1dc238a");
        return arg;
    }
    public static Map<String, Object> getEncryMap1() {
        Map<String, Object> arg = new HashMap<String, Object>();
        //arg.put("token","3d0698bac419ca50fd4abe81f75154ed");
        return arg;
    }
    public static Map<String, Object> getEncryMap(Context context) {
        Map<String, Object> arg = new HashMap<String, Object>();
        //arg.put("token","3d0698bac419ca50fd4abe81f75154ed");
        arg.put("token","acbc61ddcad5375b450ac5c6e1dc238a");
        String token = SharedUtil.getToken(context);
        if (!StringUtil.isEmpty(token)) {
           // arg.put("token",token);

            arg.put("appTk",token);
        }
        LogUtil.e("v="+token);
        return arg;
    }


}

